package com.spsoft.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.spsoft.core.enums.SysRolesTypeEnum;

import com.spsoft.core.model.Result;


import com.spsoft.core.utils.BeanUtils;
import com.spsoft.system.entity.SysRoles;
import com.spsoft.system.mapper.SysRolesMapper;
import com.spsoft.system.model.vo.SysRolesVo;
import com.spsoft.system.service.SysRolesService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * ????? 服务实现类
 * </p>
 *
 * @author dlchen
 * @since 2023-11-16
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class SysRolesServiceImpl extends ServiceImpl<SysRolesMapper, SysRoles> implements SysRolesService {

    @Override
    public Result<List<SysRolesVo>> getAllSysRoles() {
        LambdaQueryWrapper<SysRoles> w = new LambdaQueryWrapper<>();
        w.orderByAsc(SysRoles::getRoleid);
        List<SysRoles> list = this.list(w);
        List <SysRolesVo> slist= BeanUtils.copyListProperties(list, SysRolesVo::new,(s, t)->{
            t.setDeptCodeName(SysRolesTypeEnum.getInfo(s.getDeptCode()) );
            t.setRoleName(s.getRolename());
        });
        return Result.OK(slist);
    }
}
